package com.estar.integaration.strategy;

import com.estar.integaration.Parser.NaturalSentenceParse;
import com.estar.integaration.entity.paymentPlanEntity.PurchaseOrderDetail;
import com.estar.integaration.entity.paymentPlanEntity.SupplierAccountPeriod;

import java.util.List;
import java.util.Map;

/**
 * Author: YJL
 * Date: 2022/2/18 14:12
 * 未付全款-未入库-未到票 NNN
 **/
public class StrategyNNN extends Strategy {

  Map<String, SupplierAccountPeriod> supplierAccountPeriodMap = null;

  public StrategyNNN(Map<String, SupplierAccountPeriod> supplierAccountPeriodMap) {
    this.supplierAccountPeriodMap = supplierAccountPeriodMap;
  }

  @Override
  public Boolean setExpectDate(List<PurchaseOrderDetail> purchaseOrderDetailList,PurchaseOrderDetail purchaseOrderDetail,String type) {
    if(purchaseOrderDetailList == null ||
        purchaseOrderDetailList.get(0) == null||
        purchaseOrderDetailList.get(0).getDeliveryGoodsDate() == null){
      return false;
    }
    if(supplierAccountPeriodMap == null)
      return false;
    SupplierAccountPeriod supplierAccountPeriod = supplierAccountPeriodMap.get(purchaseOrderDetail.getSupplierName());
    if(supplierAccountPeriod == null){
      purchaseOrderDetailList.forEach(
          p ->
          {
            p.setExpectPayDate("未找到供应商账期");
            p.setType("NNN");
            p.setIfSpecial(false);
          }
      );
      return false;
    }
    String realNeedAddDay = supplierAccountPeriodMap.get(purchaseOrderDetail.getSupplierName()).getRealNeedAddDay();
    String deliveryGoodsDate = purchaseOrderDetail.getDeliveryGoodsDate();
    String newDate = dateAddAccountPeriod(deliveryGoodsDate,realNeedAddDay);
    purchaseOrderDetailList.forEach(
        p -> {
          p.setExpectPayDate(newDate);
          p.setNeedPayAmount(p.getPriceTaxGather());
          p.setType("NNN");
          p.setIfSpecial(false);
        }
    );
    return true;
  }
}
